<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>计数器-组合式API</title>
  </head>
  <body>
    <div id="app">
      点击了{{ count }}次
      <button @click="add">加1</button>
    </div>
  </body>
  <script src="../../lib/vue.global.js"></script>
  <script>
    const { createApp, ref } = Vue;

    const app = createApp({
      // setup 即为组合式API的标识
      setup() {
        const count = ref(100);
        console.log(count);
        console.log(count.value);

        // 自定义的函数
        const add = () => {
          count.value = count.value + 1;
        };

        return {
          // 返回view层需要的数据以及方法
          count,
          add,
        };
      },
    });

    app.mount("#app");
  </script>
</html>
